/*
 * @Author: ZWS
 * @Date: 2022-01-26 17:18:20
 * @LastEditTime: 2022-02-15 17:44:04
 * @Description: 封装localStorage
 */
// 可通过 对象操作方式来操作
const store = localStorage

export const localStorageProxy = new Proxy(store, {
  get (target: Storage, key: string): string | null {
    return target.getItem(key)
  },
  set (target: Storage, key: string, value: string): boolean {
    try {
      target.setItem(key, value)
      return true
    } catch (error) {
      return false
    }
  },
  deleteProperty (target: Storage, key: any): boolean {
    try {
      target.removeItem(key)
      return true
    } catch (error) {
      return false
    }
  }
})
